//
// Created by yangchao on 2022/5/11.
// 73. 矩阵置零 https://leetcode.cn/problems/set-matrix-zeroes/
//
#include <vector>
using namespace std;

class SetZeroes{
public:
    void setZeroes(vector<vector<int>>& matrix) {
        int m = matrix.size();
        int n = matrix[0].size();
        vector<vector<int>> pos(2);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                if (matrix[i][j] == 0) {
                    pos[0].push_back(i);
                    pos[1].push_back(j);
                }
            }
        }
        while (!pos[0].empty()) {
            int row = pos[0].back();
            for (int i = 0; i < n; ++i) {
                matrix[row][i] = 0;
            }
            pos[0].pop_back();
        }
        while (!pos[1].empty()) {
            int col = pos[1].back();
            for (int i = 0; i < m; ++i) {
                matrix[i][col] = 0;
            }
            pos[1].pop_back();
        }
    }
};
int main() {
    vector<vector<int>> matrix;
    matrix.push_back({1,1,1});
    matrix.push_back({1,0,1});
    matrix.push_back({1,1,1});

    SetZeroes sz;
    sz.setZeroes(matrix);
}

